package evaluation;

import java.io.*;
import java.net.*;
import java.util.regex.*;




public class BingDistanceCaculator {

	/**
	 * @param args
	 */
	static final long N = 100000000000L;
	 
	static double getGoogleDistance(String termA, String termB)	{
		long countA = getCount("\"" +termA + "\"");
		long countB = getCount("\"" +termB + "\"");
		long countAB = getCount("%2B\"" +termA + "\"" + "%20AND%20" + "%2B\"" +termB + "\"");
		
//		System.out.println(countA);
//		System.out.println(countB);
//		System.out.println(countAB);
		if(countA < countB)	{
			long temp = countA;
			countA = countB;
			countB = temp;
		}
		//System.out.println( (Math.log(countA) - Math.log(countAB)) + " " + (Math.log(N) - Math.log(countB)));
//		System.out.println((Math.log(countA))+ "\t"+(Math.log(N) - Math.log(countB))+" \t");
//		System.out.println(termA + " - " + termB + " "+(Math.log(countA) )/(Math.log(N) - Math.log(countB)));
		double res = (Math.log(countA)-Math.log(countAB))/(Math.log(N) - Math.log(countB));
		System.out.println(res + "\t" + termB + "%" + termA);
		return res;
	}
	
	static long getCount(String term) 	{
		//System.out.println(term);
		try {
			return BingSearcher.getWebPageNumber(term);
		} catch (Exception e) {
			 //TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//System.out.println(getCount("+Pompeii AND +Vesuvius"));
		//System.out.println(getCount("Vesuvius"));
		//getCount("\"Pompeii\" AND \"test\"");
		String termA = "Google", termB = "IBM";
		getGoogleDistance(termA,termB);
	}

}
